var url = require('url');
var template = require('templateConfig');
var main = require('main');
var form = require('form');
var module = require('module');

//模板配置
var tplArr = [];
var indexTpl =require('raw!../template/index.txt'); 
tplArr['index'] = template.compile(indexTpl.replace(/^\s*|\s*$/g, "")); 
 
var hotList = {}
function Index(){
    _this = this;
    this.main = function(){
        main.event(this,'tap','i-click'); 
        this.init();
    } 
    
    this.getContent = function(){
        main.get(url.productIndex,{},function(ret){
            //console.log(ret);
            var search = {
                click: "",
                placeholder: "热门搜索：缤纷派 热销爆款"
            }
            var hotList = {
                tType: "hotList",
                List: ret.data
            }
            
            var data = {
                tType: "content",
                //search:module.getModule(search, "search"),
                hotlist:tplArr['index'](hotList),
                //pic:tplArr['index'](pic)
            }
            
            $(".content").html(tplArr['index'](data));
            _this.getSlider();
            
        })
        
    }

    this.getFoot =function(x,y) {
        main.post(url.getCount,{store_id:x},function(ret){
        	var data = {
        		active: "0",
        		dataList: [{
        			link: url.Index,
        			icon: "ui-icon-home",
        			name: "首页"
        		},{
        			link: url.shopCar,
        			icon: "ui-icon-cart",
        			name: "购物车",
                    cornernum: ret.data
        		},{
        			link: url.Center,
        			icon: "ui-icon-personal",
        			name: "个人中心"
        		}]
                
        	}
            console.log(y);
            if(y==1){
                data.dataList[2].link="../alliance/personal-index?type=1";
            }
        	$(".wrap").append(module.getModule(data, "footer"));
        })

    }
    //轮播 
    this.getSlider = function(){
        main.get(url.indexPic,{},function(ret){
            //console.log(ret.data[0]);
            var slider = {
                tType: "pic",
                list: ret.data[0],
                pic1: ret.data[1],
                pic2: ret.data[2]
            }
            console.log(ret);
            console.log(ret.data[1]);
            $(".slider").html(tplArr['index'](slider));
            _this.slider();
        })
    }
    this.slider = function(){
        var slider = new fz.Scroll('.ui-slider', {
            role: 'slider',
            indicator: true,
            autoplay: true,
            interval: 3000
        });
    }
    
    // 跳转详情页
    this.goDetail =function(ths){
        var product_id = ths.attr("id");
        window.location.href=url.goDetail+"?id="+product_id;
    }
    
    this.init= function(){
        //main.confirm();
        this.storeId=store_id;
        this.status=role;
        this.getFoot(this.storeId,this.status);
        this.getContent();
        
    }
    return this.main();
};

var index = new Index();